package com.ncui.wisdomLearn.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redisson配置类
 *
 * @author lvlele
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.data.redis.host}")
    private String host;

    @Value("${spring.data.redis.port}")
    private int port;

    @Value("${spring.data.redis.database}")
    private int database;

    @Value("${spring.data.redis.timeout}")
    private int timeout;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port)
                .setDatabase(database)
                .setConnectTimeout(timeout)
                .setConnectionMinimumIdleSize(24)
                .setConnectionPoolSize(64)
                .setIdleConnectionTimeout(10000)
                .setRetryAttempts(3)
                .setTimeout(3000);

        config.setThreads(16);
        config.setNettyThreads(32);
        config.setTransportMode(org.redisson.config.TransportMode.NIO);

        return Redisson.create(config);
    }
} 